package cn.mlamp4;

import java.util.Arrays;

import static java.lang.Math.*;

/**
 * 360度 = 2Pi弧度
 * 90度 = 2 * π / 360 * 90 弧度
 *
 * @author tzp
 * @since R/10/22
 */
public class Heart {
    public static final int CNT = 1024;
    public static final int R = 2020;

    public static int[][] all;
    public static int[][] all1;

    static {
        all = polar();
        all1 = Arrays.copyOf(all, all.length);
        all1[512] = new int[]{-2020, 0};//舍入问题
    }

    public static void main(String[] args) {
        String s = "";
        for (int[] ints : polar()) {
            s += ints[0] + "," + ints[1] + "\n";
        }

        System.out.println(sin(PI));
        double r = R * (1 - sin(PI));
        double x = r * cos(PI);
        double y = r * sin(PI);
        System.out.println(x);
        System.out.println(y);
        System.out.println((int) x);
        System.out.println((int) y);
    }


    /**
     * r = a (1-sin θ)
     * 每次转过固定角度, 转CNT个点, 初始r长度R
     */
    public static int[][] polar() {
        int[][] result = new int[CNT][2];
        for (int i = 0; i < CNT; i++) {
            double xita = i * 2 * PI / CNT;
//            double jiaodu = 360 * xita / (2 * PI);
            double r = R * (1 - sin(xita));
            double x = r * cos(xita);
            double y = r * sin(xita);
//            System.out.println("[" + r + "," + jiaodu + "],");
            result[i] = new int[]{(int) x, (int) y};
        }
        return result;
    }

    public static void cartesian() {
        for (int i = 0; i < CNT; i++) {
            double xita = i * 2 * PI / CNT;
            double jiaodu = 360 * xita / (2 * PI);
            double y = R * (2 * cos(xita) - cos(2 * xita));
            double x = R * (2 * sin(xita) - sin(2 * xita));

            System.out.println("[" + x + "," + y + "],");
        }
    }

}
